package 实验五;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		String str = "汉皇重色思倾国御宇多年求不得杨家有女初长成养在深闺人未识天生丽质难自弃一朝选在君王侧回眸一笑百媚生六宫粉黛无颜色春寒赐浴华清池温泉水滑洗凝脂侍儿扶起娇无力始是新承恩泽时云鬓花颜金步摇芙蓉帐暖度春宵春宵苦短日高起从此君王不早朝承欢侍宴无闲暇春从春游夜专夜后宫佳丽三千人三千宠爱在一身金屋妆成娇侍夜玉楼宴罢醉和春姊妹弟兄皆列士可怜光采生门户遂令天下父母心不重生男重生女骊宫高处入青云仙乐风飘处处闻缓歌慢舞凝丝竹尽日君王看不足渔阳鼙鼓动地来惊破霓裳羽衣曲九重城阙烟尘生千乘万骑西南行";
		int i;
		
		Scanner sc = new Scanner(System.in);
		StringBuffer s1 = new StringBuffer(str);
		
		String findStr = sc.nextLine();
		
		for(i = s1.length(); i>0; i-=14) {
			s1.insert(i,'\n');
			s1.insert(i,'。');
		}
		for(i = s1.length() - 9; i>0; i-=16) {
			s1.insert(i,',');
		}
	    
	    int count=0;
	    int total=0;
	    while(str.indexOf(findStr,total)>=0){
	         count++;
	         total=str.indexOf(findStr,total)+findStr.length();
	    }
	    
	    String str1 = s1.toString();
	    
	    File file = new File("./file/shige.txt");
        if(!file.exists()){
            file.getParentFile().mkdir();
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
        	FileOutputStream fileOut = new FileOutputStream("./file/shige.txt");
        	ObjectOutputStream out = new ObjectOutputStream(fileOut);
        	PrintWriter pw = new PrintWriter(out);
        	pw.print(new String(str1.getBytes(),"gbk"));
        	pw.close();
        	System.out.printf("Data saved in /file/shige.txt"+"\n");
        }catch(Exception a){
        	a.printStackTrace();
        }
	    
        System.out.println(str1);
	    System.out.println(findStr+" "+"共出现"+count+"次");
	    sc.close();
	}
}